home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / c / flash-0.4.3.lha / flash-0.4.3 / Lib / shape.h < prev    next >
C/C++ Source or Header  |  1999-02-21  |  4KB  |  191 lines

  1. /////////////////////////////////////////////////////////////
  2. // Flash Plugin and Player
  3. // Copyright (C) 1998,1999 Olivier Debon
  4. // 
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. // 
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. // 
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. // 
  19. ///////////////////////////////////////////////////////////////
  20. #ifndef _SHAPE_H_
  21. #define _SHAPE_H_
  22.  
  23. #include "character.h"
  24. #include "bitmap.h"
  25. #ifdef DUMP
  26. #include "bitstream.h"
  27. #endif
  28.  
  29. enum FillType {
  30.     f_Solid          = 0x00,
  31.     f_LinearGradient = 0x10,
  32.     f_RadialGradient = 0x12,
  33.     f_TiledBitmap    = 0x40,
  34.     f_clippedBitmap  = 0x41
  35. };
  36.  
  37. struct FillStyleDef {
  38.     FillType     type;    // See enum FillType
  39.  
  40.     // Solid
  41.     Color         color;
  42.  
  43.     // Gradient
  44.     Gradient     gradient;
  45.  
  46.     // Bitmap
  47.     Bitmap        *bitmap;
  48.     SwfPix        *pix;
  49.     long         xOffset,yOffset;
  50.  
  51.     // Gradient or Bitmap
  52.     Matrix         matrix;
  53. };
  54.  
  55. struct LineStyleDef {
  56.     long         width;
  57.     Color         color;
  58. };
  59.  
  60. enum ShapeRecordType {
  61.     shapeNonEdge,
  62.     shapeCurve,
  63.     shapeLine
  64. };
  65.  
  66. enum ShapeFlags {
  67.     flagsMoveTo       = 0x01,
  68.     flagsFill0       = 0x02,
  69.     flagsFill1       = 0x04,
  70.     flagsLine       = 0x08,
  71.     flagsNewStyles       = 0x10,
  72.     flagsEndShape        = 0x80
  73. };
  74.  
  75. struct ShapeRecord {
  76.     ShapeRecordType  type;
  77.  
  78.     // Non Edge
  79.     ShapeFlags     flags;
  80.     long         x,y;    // Moveto
  81.     long         fillStyle0;
  82.     long         fillStyle1;
  83.     long         lineStyle;
  84.     FillStyleDef    *newFillStyles; // Array
  85.     long         nbNewFillStyles;
  86.     LineStyleDef    *newLineStyles; // Array
  87.     long         nbNewLineStyles;
  88.  
  89.     // Curve Edge
  90.     long         ctrlX, ctrlY;
  91.     long         anchorX, anchorY;
  92.  
  93.     // Straight Line
  94.     long         dX,dY;
  95.  
  96.     struct ShapeRecord *next;
  97. };
  98.  
  99. enum ShapeAction {
  100.     ShapeDraw,
  101.     ShapeGetRegion
  102. };
  103.  
  104. struct SPoint {
  105.     long         x,y;
  106.     long         X,Y;
  107.     FillStyleDef    *f0;
  108.     FillStyleDef    *f1;
  109.     LineStyleDef    *l;
  110.     int         curve;
  111.  
  112.     struct SPoint     *next;
  113.  
  114.     SPoint(long x, long y, FillStyleDef *f0, FillStyleDef *f1, LineStyleDef *l)    //Constructor
  115.     {
  116.         this->x = x;
  117.         this->y = y;
  118.         this->f0 = f0;
  119.         this->f1 = f1;
  120.         this->l = l;
  121.         curve = 0;
  122.         next = 0;
  123.     };
  124. };
  125.  
  126. struct Segment {
  127.     long         ymin, x1;
  128.     long         ymax, x2;
  129.     FillStyleDef    *fs[2];    // 0 is left 1 is right
  130.     int         aa;
  131.     long         dX;
  132.     long         X;
  133.  
  134.     struct Segment *next;
  135.     struct Segment *nextValid;
  136. };
  137.  
  138. struct Path {
  139.     SPoint        *path;
  140.     FillStyleDef    *fillStyles;    // Array
  141.     long         nbFillStyles;
  142.     LineStyleDef    *lineStyles;    // Array
  143.     long         nbLineStyles;
  144. };
  145.  
  146. class Shape : public Character {
  147.     int         defLevel; // 1,2 or 3
  148.     FillStyleDef    *fillStyles;    // Array
  149.     long         nbFillStyles;
  150.     LineStyleDef    *lineStyles;    // Array
  151.     long         nbLineStyles;
  152.     ShapeRecord    *shapeRecords;
  153.     Rect         boundary;
  154.     Path        *path;
  155.     long         nbPath;
  156.     FillStyleDef     defaultFillStyle;
  157.     LineStyleDef     defaultLineStyle;
  158.  
  159.     Matrix         lastMat;
  160.  
  161. protected:
  162.     void     drawLines(GraphicDevice *gd, Matrix *matrix, Cxform *cxform, long, long);
  163.     void     buildSegmentList(Segment **segs, int height, long &n, Matrix *matrix, int update, int reverse);
  164.     Segment *progressSegments(Segment *, long);
  165.     Segment *newSegments(Segment *, Segment *);
  166.  
  167. public:
  168.     Shape(long id = 0 , int level = 1);
  169.     ~Shape();
  170.  
  171.     void     setBoundingBox(Rect rect);
  172.     void     setFillStyleDefs(FillStyleDef *defs,long n);
  173.     void     setLineStyleDefs(LineStyleDef *defs,long n);
  174.     void     addShapeRecord(ShapeRecord  *sr);
  175.     int     execute(GraphicDevice *gd, Matrix *matrix, Cxform *cxform);
  176.     void     getRegion(GraphicDevice *gd, Matrix *matrix, unsigned char id);
  177.     void     doShape(GraphicDevice *gd, Matrix *matrix, Cxform *cxform, ShapeAction shapeAction, unsigned char id);
  178.     void     buildShape();
  179.     Rect     getBoundingBox();
  180.  
  181. #ifdef DUMP
  182.     void     dump(BitStream *bs);
  183.     void     dumpShapeRecords(BitStream *bs, int alpha);
  184.     void     dumpFillStyles(BitStream *bs, FillStyleDef *defs, long n, int alpha);
  185.     void     dumpLineStyles(BitStream *bs, LineStyleDef *defs, long n, int alpha);
  186.     void     checkBitmaps(BitStream *bs);
  187. #endif
  188. };
  189.  
  190. #endif /* _SHAPE_H_ */
  191.